package com.dao.zk;

import com.bean.zk.Log;
import com.util.zk.Dbutil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.MapListHandler;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

@Repository
public class IndexPowerDAO {

    public List<Map<String, Object>> selUrlByEid(Integer eid) {
        Connection con = null;
        QueryRunner query = new QueryRunner();
        List<Map<String, Object>> urls = null;
        try {
            con = Dbutil.getConnection();
            String sql = "select distinct(p.power_url) as url from power p, emp e, emp_role er, role r ,role_power rp\n" +
                    " where p.power_id = rp.power_id and e.eid = er.eid and r.rid = rp.rid and er.rid = r.rid and e.eid = ?";
             urls = query.query(con, sql, new MapListHandler(), eid);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            Dbutil.closeAll(null,null,con);
        }
        return urls;
    }
}
